<?php
require_once __DIR__.'/PHPExcel/Classes/PHPExcel.php';
$excel=new PHPExcel();
if ($_POST['a']==99)
{
    $sheet=$excel->setActiveSheetIndex(0);//设置工作簿
//$sheet->setTitle('work1');设置工作簿名称
    $arr=range('A','Z');
    for ($a=1;$a<10;$a++)
    {
        for ($b=1;$b<=$a;$b++)
        {
            echo ' '.$b.'*'.$a.'='.$a*$b;
            echo $arr[$b-1]."$a";
            $sheet->setCellValue($arr[$b-1]."$a",$b.'*'.$a.'='.$a*$b);//设置单元格的值*/
        }
        echo "<br/>";
    }
    $create=PHPExcel_IOFactory::createWriter($excel,'Excel2007');//生成excel, Excel2007 版本的后缀名.xlsx
    $create->save(__DIR__.'/5.xlsx');//保存到哪里save(路径）
    echo 'ok';
}
if ($_POST['a1']==991)
{
    $excel=PHPExcel_IOFactory::createReader('Excel2007');
    $read=$excel->load(__DIR__.'/5.xlsx');
    $sheet=$read->getSheet(0);
    $arr=range('A','Z');
    $att=array();
    for ($a=1;$a<10;$a++)
    {
        for ($b=1;$b<=$a;$b++)
        {
            $sheet->setCellValue($arr[$b-1]."$a",$b.'*'.$a.'='.$a*$b);//设置单元格的值*/
            $att[$a][]=$sheet->getCell($arr[$b-1]."$a")->getValue();
        }
    }
    echo json_encode($att);
}


